#ifndef __CHANNEL_HPP__
#define __CHANNEL_HPP__

#include <iostream>
#include <string>
#include <unistd.h>
class Channel
{
public:
    Channel(int wfd, pid_t who) : _wfd(wfd), _who(who)
    {
        _name = "Channel-" + std::to_string(wfd) + "-" + std::to_string(who);
    }
    std::string Name()
    {
        return _name;
    }
    void Send(int cmd) // 派发任务
    {
        ::write(_wfd, &cmd, sizeof(cmd));
    }
    pid_t getPid() const { return _who; } // 新增：获取子进程 PID
    int getWfd() const { return _wfd; }   // 新增：获取管道写端 FD
    ~Channel() {}
    void Close()
    {
        ::close(_wfd);
    }
private:
    int _wfd;
    std::string _name;
    pid_t _who;
};


#endif 